package com.codemes.happylist.modules.music;

import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;

/**
 * @author nscoffee
 */
public enum MediaPlayerModel {

    /** 列表循环 */
    MODEL_LOOP(0,"列表循环","play-model-loop"),
    /** 随机播放 */
    MODEL_RANDOM(1,"随机播放","play-model-random"),
    /** 单曲循环 */
    MODEL_SINGLE(2,"单曲循环","play-model-single"),
    ;

    /** 样式类名*/
    private String className;
    /** 模式名称*/
    private String modelName;
    /** 索引*/
    private Integer index;

    MediaPlayerModel(Integer index,String modelName,String className){
        this.className=className;
        this.modelName=modelName;
        this.index=index;
    }

    public static MediaPlayerModel getByIndex(Integer index){
        return Arrays.stream(MediaPlayerModel.values()).filter(model -> {
            return model.getIndex().intValue() == index.intValue();
        }).findFirst().orElse(null);
    }

    public static MediaPlayerModel nextModel(MediaPlayerModel curModel) {
        Integer index = curModel.getIndex();
        index++;
        Integer total = MediaPlayerModel.values().length;
        Integer nextIndex = index%total;
        Optional<MediaPlayerModel> nextModelOpts = Arrays.stream(MediaPlayerModel.values()).filter(model -> {
            return model.getIndex().equals(nextIndex);
        }).findFirst();
        return nextModelOpts.orElse(MODEL_LOOP);
    }

    public String getClassName() {
        return className;
    }

    void setClassName(String className) {
        this.className = className;
    }

    public String getModelName() {
        return modelName;
    }

    void setModelName(String modelName) {
        this.modelName = modelName;
    }

    public Integer getIndex() {
        return index;
    }

    void setIndex(Integer index) {
        this.index = index;
    }
}
